function(yoohoo_add_library2 yoohoo_source_dir yoohoo_module_name)
	unset(YOOHOO_MODULE_SRCS)
	unset(YOOHOO_MODULE_NON_QOBJECT_HDRS)
	unset(YOOHOO_MODULE_QOBJECT_HDRS)
	unset(YOOHOO_MODULE_MOC_SRCS)

	file(GLOB header_files ${yoohoo_source_dir}/include/${yoohoo_module_name}/*.h)
	foreach(header ${header_files})
		set(YOOHOO_FIND_QOBJECT 0)
		file(STRINGS ${header} code_lines LIMIT_COUNT 200)
		foreach(code_line ${code_lines})
			if(${code_line} MATCHES [\\s\\t]*Q_OBJECT[\\s\\t]*)
				set(YOOHOO_MODULE_QOBJECT_HDRS ${YOOHOO_MODULE_QOBJECT_HDRS} ${header})
				set(YOOHOO_FIND_QOBJECT 1)
				break()
			endif(${code_line} MATCHES [\\s\\t]*Q_OBJECT[\\s\\t]*)
		endforeach(code_line ${code_lines})
		if(NOT YOOHOO_FIND_QOBJECT)
			set(YOOHOO_MODULE_NON_QOBJECT_HDRS ${YOOHOO_MODULE_NON_QOBJECT_HDRS} ${header})
		endif(NOT YOOHOO_FIND_QOBJECT)
	endforeach(header ${header_files})
	
	file(GLOB YOOHOO_MODULE_SRCS ${yoohoo_source_dir}/src/${yoohoo_module_name}/*.cpp)
	
	if(WIN32)
		if(DEFINED YOOHOO_MODULE_QOBJECT_HDRS)
			set(YOOHOO_MODULE_SRCS ${YOOHOO_MODULE_SRCS} ${YOOHOO_MODULE_QOBJECT_HDRS})
		endif(DEFINED YOOHOO_MODULE_QOBJECT_HDRS)
		
		if(DEFINED YOOHOO_MODULE_NON_QOBJECT_HDRS)
			set(YOOHOO_MODULE_SRCS ${YOOHOO_MODULE_SRCS} ${YOOHOO_MODULE_NON_QOBJECT_HDRS})
		endif(DEFINED YOOHOO_MODULE_NON_QOBJECT_HDRS)
	endif(WIN32)

	
	if(DEFINED YOOHOO_MODULE_QOBJECT_HDRS)
		qt4_wrap_cpp(YOOHOO_MODULE_MOC_SRCS ${YOOHOO_MODULE_QOBJECT_HDRS})
	endif(DEFINED YOOHOO_MODULE_QOBJECT_HDRS)
	
	if(DEFINED YOOHOO_MODULE_MOC_SRCS)
		add_library(${yoohoo_module_name} SHARED ${YOOHOO_MODULE_SRCS} ${YOOHOO_MODULE_MOC_SRCS})
	else(DEFINED YOOHOO_MODULE_MOC_SRCS)
		add_library(${yoohoo_module_name} SHARED ${YOOHOO_MODULE_SRCS})
	endif(DEFINED YOOHOO_MODULE_MOC_SRCS)

endfunction(yoohoo_add_library2 yoohoo_source_dir yoohoo_module_name)

function(yoohoo_add_library yoohoo_module_name)
	yoohoo_add_library2(${PROJECT_SOURCE_DIR} ${yoohoo_module_name})
endfunction(yoohoo_add_library yoohoo_module_name)

function(yoohoo_add_test_with_depended_libraries test_name depended_libraries)
	qt4_wrap_cpp(${test_name}_moc_src ${test_name}.h)
	if(WIN32)
		add_executable(${test_name} ${${test_name}_moc_src} ${test_name}.h ${test_name}.cpp)
	else(WIN32)
		add_executable(${test_name} ${${test_name}_moc_src} ${test_name}.cpp)
	endif(WIN32)

	set(ADJUSTED_LIBRARIES)
	foreach(library ${depended_libraries})
		set(ADJUSTED_LIBRARIES ${ADJUSTED_LIBRARIES} ${YOOHOO_BUILD_TYPE} ${library})
	endforeach(library ${depended_libraries})

	add_test(${test_name} ${PROJECT_BINARY_DIR}/test/${YOOHOO_TEST_MODULE_NAME}/bin/${test_name})
	target_link_libraries(${test_name} ${QT_LIBRARIES} ${ADJUSTED_LIBRARIES})
endfunction(yoohoo_add_test_with_depended_libraries test_name depended_libraries)

function(yoohoo_add_test test_name)
	yoohoo_add_test_with_depended_libraries(${test_name} ${YOOHOO_TEST_MODULE_NAME})
endfunction(yoohoo_add_test test_name)

function(yoohoo_create_dummy_target target_name)
	if(NOT WIN32)
		return()
	endif(NOT WIN32)

	add_custom_target(${target_name} ALL)
endfunction(yoohoo_create_dummy_target target_name)

function(yoohoo_copy_basic_libraries_to_test_binary_dir test_module_name)
	if(NOT WIN32)
		return()
	endif(NOT WIN32)
	
	if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
		set(YOOHOO_TEST_DEPENDED_DLLS
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtCored4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtGuid4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtNetworkd4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtTestd4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/libeay32.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/libsasl.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/ssleay32.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/qcad2.dll
		)
	else(${CMAKE_BUILD_TYPE} MATCHES "Release")
		set(YOOHOO_TEST_DEPENDED_DLLS
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtCore4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtGui4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtNetwork4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/qt/QtTest4.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/libeay32.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/libsasl.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/ssleay32.dll
			${PROJECT_SOURCE_DIR}/thirdparty/lib/qca2.dll
		)
	endif(${CMAKE_BUILD_TYPE} MATCHES "Debug")

	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E make_directory
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)
	
	foreach(depended_dll ${YOOHOO_TEST_DEPENDED_DLLS})
		add_custom_command(TARGET ${test_module_name}_test_dummy
			POST_BUILD
			COMMAND ${CMAKE_COMMAND} -E copy_if_different
			${depended_dll}
			${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
		)
	endforeach(depended_dll ${YOOHOO_TEST_DEPENDED_DLLS})

endfunction(yoohoo_copy_basic_libraries_to_test_binary_dir test_module_name)

function(yoohoo_copy_library_to_test_binary_dir test_module_name depended_library)
	if(NOT WIN32)
		return()
	endif(NOT WIN32)
	
	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E make_directory
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)
	
	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/${depended_library}.dll
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)
endfunction(yoohoo_copy_library_to_test_binary_dir test_module_name depended_library)

function(yoohoo_copy_extension_library_to_test_binary_dir test_module_name library_type library_name)
	if(NOT WIN32)
		return()
	endif(NOT WIN32)
	
	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E make_directory
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)
	
	set(YOOHOO_TEST_DEPENDED_DLL ${PROJECT_BINARY_DIR}/tmp/${library_type}/${library_name}/${CMAKE_BUILD_TYPE}/${library_name}.dll)
	
	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		${YOOHOO_TEST_DEPENDED_DLL}
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)

endfunction(yoohoo_copy_extension_library_to_test_binary_dir test_module_name library_type library_name)

function(yoohoo_copy_extension_library_to_updates_dir library_type library_name)
	if(NOT WIN32)
		return()
	endif(NOT WIN32)
	
	add_custom_command(TARGET ${library_name}_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E make_directory
		${PROJECT_BINARY_DIR}/updates/${library_name}
	)
	
	set(YOOHOO_TEST_DEPENDED_DLL ${PROJECT_BINARY_DIR}/tmp/${library_type}/${library_name}/${CMAKE_BUILD_TYPE}/${library_name}.dll)
	
	add_custom_command(TARGET ${test_module_name}_test_dummy
		POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different
		${YOOHOO_TEST_DEPENDED_DLL}
		${PROJECT_BINARY_DIR}/test/${test_module_name}/bin/${CMAKE_BUILD_TYPE}
	)

endfunction(yoohoo_copy_extension_library_to_updates_dir library_type library_name)
